Add Two Integers using C Program

07-11-17 Course- C

Program to Add Two Integers


#include <stdio.h>
int main()
{
    int firstN, secondN, sumOfTwoN;
    
    printf("Enter two integers: ");

    // Two integers entered by user is stored using scanf() function
    scanf("%d %d",&firstN, &secondN);

    // sum of two numbers in stored in variable sumOfTwoNumbers
    sumOfTwoN = firstN + secondN;

    // Displays sum      
    printf("%d + %d = %d", firstN, secondN, sumOfTwoN);

    return 0;
}

Output


Enter two integers: 12
11
12 + 11 = 23

In this program, user is asked to enter two integers. Two integers entered by the user is stored in variables firstNumber and secondNumber respectively. This is done using scanf() function.

Then, variables firstNumber and secondNumber is added using + operator and the result is stored in sumOfTwoNumbers.

Finally, the sumofTwoNumbers is displayed on the screen using printf() function.